﻿
function goback(hardid){
    if (window.confirm('你确定要退回吗？')) {
        $.ajax({
            type: "post",
            url: "/ashx/HardWare.ashx",
            data: {
                rType: 'goback'
                   , hardid: hardid
            },
            error: function (XmlHttpRequest, textStatus, errorThrown) {
                alert(XmlHttpRequest.status);
                alert("提交失败！")
            },
            success: function (msg) {
                location.reload();
            }
        });
        return true;
    } else {
        //alert("取消");
        return false;
    }
}

function cancel() {
    location.reload();
}


//初检弹出1
function gocheck(hardid) {
    $("#hidHardid").val(hardid);
 
    //取值
    $.ajax({
        type: "post",
        url: "/ashx/HardWare.ashx",
        data: {
            rType: 'm'
                   , mid: hardid
        },
        error: function (XmlHttpRequest, textStatus, errorThrown) {
            alert(XmlHttpRequest.status);
            alert("提交失败！")
        },
        success: function (msg) {
            //值显示
            var o = eval('(' + msg + ')');
            $("#lblno").html(o.hardwareno);
            $("#lblbcity").html(o.bcity);
            $("#lblgcity").html(o.gcity);
            $("#lblcjo").html(o.cjono);
            $("#lblload").html(o.cjono);
            $("#lblcumname").html(o.cumname);
            $("#lblman").html(o.sealman);
            $("#lblcjoremark").html(o.cjoremark);
            $("#lblcolldate").html(o.wrldate);
            $("#lblcount").html(o.boxcount);
            $("#txtinitremark").val(o.initremark);
            var myDate = new Date();
            $("#lblgodate").html(o.inspectiondate);
            //弹出框
            $("#attlist").html("");
            $("#tabreord").dialog({
                width: 400,
                height: 300,
                resizable: false,
                position: 'center',
                title: '初检送检',
                modal: true
            });

            $.ajax({
                type: "post",
                url: "/ashx/HardWare.ashx",
                data: {
                    rType: 'attlist'
                   , mid: hardid
                   , CStep: 1
                },
                dataType: 'json',
                error: function (XmlHttpRequest, textStatus, errorThrown) {
                    alert(XmlHttpRequest.status);
                    alert("提交失败！")
                },
                success: function (msg) {
                   
                    if (msg != null ) {

                        var html = "";
                        $.each(msg, function (index, v) {
                            html = html + "<dd><a>" + v.AttacheName + "</a><a href='javascript:void(0);' onclick='delatt(" + v.id + ")'>删除</a></dd>";
                        });
                        $("#attlist").html(html);
                    }
                }
            });
        }
    });


}

//初检弹出提交
function gocheckSubmit() {
    var checkstatus = $("#gotype").val();
 
    if (checkstatus == '0') {
        alert("请选择是否硬件测试");
        return;
    } 
    else {

        var myDate = new Date();
        var idate = myDate.toLocaleDateString();
        //弹出框
        $.ajax({
            type: "post",
            url: "/ashx/HardWare.ashx",
            data: {
                rType: "Hard"
               , hardid: $("#hidHardid").val()
               , initremark: $("#txtinitremark").val()
               , initdate: idate
               , step1: checkstatus
            },
            error: function (XmlHttpRequest, textStatus, errorThrown) {
                alert(XmlHttpRequest.status);
                alert("提交失败！")
            },
            success: function (msg) {
                alert("已经送检");
                location.reload();
            }
        });
    }
    

}


$(document).ready(function () {

    $("#rdoHard,#rdoNoHard").click(function () {
        if ($(this).attr('id') == 'rdoHard') {
            $("#gotype").val("2");  //待硬件检测
        }
        else if ($(this).attr('id') == 'rdoNoHard') {
            $("#gotype").val("3");  //直接理货备注
        }
        
    });

    $('#tab').dataTable({ "oLanguage":
                 { "sUrl": "/jquery/jquery.dataTable.cn.txt" },
        "bJQueryUI": true,
        "sPaginationType": "full_numbers",
        'bPaginate': true,
        "bProcessing": true,
        "iDisplayLength": 20,
        "bSort": true,
        "aaSorting": [[0, "desc"]]
    });

    $("#tabreord").hide();
});

//文件上传
function ajaxFileUpload() {
    
    var param = "hardid=" + $("#hidHardid").val();
    param += "&CStep=1&rType=upatt";
    
  
    var x = document.getElementById("uploadatt");
    if (!x || !x.value) return;


    var elementIds = ["uploadatt"]; //flag为id、name属性名
    $.ajaxFileUpload({
        url: '/ashx/HardWare.ashx?' + param, //上传的url，根据自己设置
        type: 'post',
        secureuri: false, //一般设置为false
        fileElementId: 'uploadatt', // 上传文件的id、name属性名
        dataType: 'json', //返回值类型，一般设置为json、application/json
        elementIds: elementIds, //传递参数到服务器
        success: function (data, status) {
            //处理JSON
            d = data;
            var start = d.indexOf("{");
            if (start != -1) {
                var end = d.indexOf("}", start + 1);
                if (end != -1) {
                    d = d.substring(start, end+1);
                }
            }
           
            var jsonData = $.parseJSON(d);
            
            var html = $("#attlist").html();
            html = html + "<dd><a>" + jsonData.AttacheName + "</a><a href='javascript:void(0);' onclick='delatt(" + jsonData.id + ")'>删除</a></dd>";
            $("#attlist").html(html);
        },
        error: function (data, status, e) {
            alert(e);
        }
    });

}

//删除附件
function delatt(attid) {
    alert(attid);
    $.ajax({
        type: "post",
        url: "/ashx/HardWare.ashx",
        dataType:"json",
        data: {
            rType:"delatt"
           , attid: attid
        },
        error: function (XmlHttpRequest, textStatus, errorThrown) {
            alert(XmlHttpRequest.status);
            alert("提交失败！")
        },
        success: function (msg) {
            if (msg != null) {

                var html = "";
                $.each(msg, function (index, v) {
                    html = html + "<dd><a>" + v.AttacheName + "</a><a href='javascript:void(0);' onclick='delatt(" + v.id + ")'>删除</a></dd>";
                });
                $("#attlist").html(html);
            }
        }
    });
}